<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="multipart/form-data">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>商品上架后台</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
<%--    <script src="js/jquery-2.2.3.min.js"></script>--%>
    <script src="js/jquery.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/admin.js"></script>
    <script src="js/ajaxfileupload.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">皮皮虾小魔仙后台</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <img src="images/bid_new.gif" class="layui-nav-img">${name}
            </li>
            <li class="layui-nav-item"><a href="index.jsp" target="_top" id="out">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">查看订单</a>
                    <dl class="layui-nav-child">
                        <dd><a onclick="allorders()">所有订单</a></dd>
                        <dd><a onclick="unisokorders()">未确认订单</a></dd>
                        <dd><a onclick="isokorders()">已确认订单</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">商品查看</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" onclick="goodshow(0)">所有商品</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(1)">美食</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(2)">饮品</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(3)">水果</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="javascript:;" onclick="userset()">账户管理</a></li>
                <li class="layui-nav-item"><a href="admin_goods.jsp">发布商品</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body" id="main_are" style="text-align: center">
        <table class="table table-hover text-center" style="text-align: center;font-size: 20px" border="1" id="goodstable">
            <tr>
                <th style="width: 50px">商品名称</th>
                <th style="width: 300px">商品图片</th>
                <th style="width: 50px">商品价格</th>
                <th style="width: 100px">商品类型</th>
            </tr>
            <form action="add_goods.do" method="post" id="add_goods_form" enctype="multipart/form-data">
                <tr style="text-align: center">
                    <td><input type="text" name="goods_name"  id="goods_name" size="10"  style="border: none;text-align: center"></td>
                    <td align="center" width="400px">
                        <img src="" id="showwimg" height="200px" width="300px" ><br>
                        <input type="file" id="inputimg"  name="goods_url" accept="image/*" onchange="showimgs()" align="center" width="100px" style="float: left;"><br>
<%--                        <input type="button" onclick="sendimg()" value="提交图片" style="float: left;"></button>--%>
                    </td>
                    <td><input type="text" name="goods_price"  id="goods_price" size="10" style="border: none;text-align: center"></td>
                    <td>
                        <select name="goods_type" id="goods_type">
                            <option value="1">中国美食</option>
                            <option value="2">日韩料理</option>
                            <option value="3">特色小吃</option>
                            <option value="4">西餐</option>
                            <option value="5">热饮</option>
                            <option value="6">冷饮</option>
                            <option value="7">酒水</option>
                            <option value="8">有机水果</option>
                            <option value="9">生鲜</option>
                        </select>
                    </td>
                </tr>
            </form>
            <tr>
                <td colspan="4" align="center"><button type="button" class="layui-btn"  onclick="add_goods_form()">添加商品</button></td>
            </tr>
        </table>
    </div>
    <div class="layui-footer">
        © 皮皮虾小魔仙外卖.com
    </div>
</div>
</body>
<script>
    function add_goods_form() {//上传图片
        var goods_name=document.getElementById("goods_name").value;
        var goods_price=document.getElementById("goods_price").value;
        var goods_type=document.getElementById("goods_type").value;
        var reads=new FileReader();
        f=document.getElementById("inputimg").files[0];
        if(goods_name==''||goods_price==''||goods_type==''){
            alert("请补齐信息!");
            return;
        }
        else if(f==''||f==null){
            alert("请上传图片");
            return;
        }
        $.ajaxFileUpload({
            url:"upimg.do",
            fileElementId : "inputimg",
            type: "POST",
            dataType:"text",
            data:{goods_name:goods_name,goods_price:goods_price,goods_type:goods_type},
            secureuri : false,
            success:function (data,status) {
                alert("商品添加成功成功");
            },
            error:function (data,status,e) {
                alert("文件上传失败");
            },
        });
    }
    function showimgs() {//图片显示
        var reads=new FileReader();
        f=document.getElementById("inputimg").files[0];
        reads.readAsDataURL(f);
        reads.onload=function(e){
            document.getElementById("showwimg").src=this.result;
        }
    }
</script>
<script>
    var websocket=null;
    if('WebSocket' in window){
        websocket=new WebSocket('ws://localhost:8080<%=path%>/webSocket');
    }else{
        alert("该浏览器不支持websocket");
    }
    websocket.onopen=function (event) {
        console.log('建立链接');
    }
    websocket.onclose=function (event) {
        console.log('链接关闭');
    }
    websocket.onmessage=function (event) {
        console.log('收到消息'+event.data)
        //消息提醒
        layer.confirm("你有新的订单", {
                but: ['我看看', '懒得看'],}
            ,function () {
                $.ajax({
                    url: "unisokorders.do",
                    type: "POST",
                    success: function () {
                        window.location.href = "admin.jsp";
                    }
                })
            }
        );
    }
    websocket.onerror=function (event) {
        alert("发生错误");
    }
    window.onbeforeunload=function () {
        websocket.close();
    }
</script>
</html>

